//
//  ButtonView.m
//  reacticons
//
//  Created by Nong Nghia on 6/29/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ButtonView.h"
#import <QuartzCore/QuartzCore.h>
#define LEFT_TAB 10
#define RIGHT_TAB 10
#define BOTTOM_TAB 10
#define TEXT_HEIGHT 50
@implementation ButtonView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        textLabel=[[UILabel alloc] initWithFrame:CGRectZero];
        btn=[[UIButton alloc] initWithFrame:CGRectZero];

        self.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        self.alpha=1;
        self.layer.cornerRadius=8;
        self.layer.borderWidth=2;
        self.layer.borderColor=[UIColor whiteColor].CGColor;
        [self addSubview:textLabel];
        [self insertSubview:btn aboveSubview:textLabel];
    }
    return self;
}

-(void)setText:(NSString*)inputText{
    [textLabel setFrame:CGRectMake( 0, 
                                    0, 
                                    self.frame.size.width-LEFT_TAB-RIGHT_TAB, 
                                    TEXT_HEIGHT)];
    [textLabel setCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/2)];
    [textLabel setFont:[UIFont systemFontOfSize:25]];
    [textLabel setText:inputText];
    [textLabel setTextColor:[UIColor whiteColor]];
    [textLabel setTextAlignment:UITextAlignmentCenter];
    [textLabel setBackgroundColor:[UIColor clearColor]];
}
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents{
    [btn setTag:self.tag];
    [btn setFrame:CGRectMake( 0, 
                                   0, 
                                   self.frame.size.width, 
                                   self.frame.size.height)];
    [textLabel setCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/2)];
    [btn addTarget:target action:action forControlEvents:controlEvents];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
